<?php

declare(strict_types=1);

namespace app\api\controller;

use app\common\model\User as UserModel;
use app\common\tool\Result;
use think\exception\ValidateException;
use app\common\model\Signup;

class User extends Base
{

    /**
     * 用户资料
     */
    public function getUserInfo()
    {
        try {
            $data=[
                'id'=>$this->user->id,
                'rname'=>$this->user->rname,
                'photo'=>$this->user->photo,
                'sexText'=>$this->user->sexText,
                'age'=>$this->user->age,
                'birth'=>$this->user->birth,
                'cateText'=>$this->user->cateText,
                'content'=>$this->user->content,
                'mobile'=>substr_replace($this->user->mobile, '*****', 3, 4),
                'id_card'=>substr_replace($this->user->id_card, '*************', 4, 10)
            ];
            return Result::success('获取成功！', $data);
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
    /**
     * 编辑资料
     */
    public function edit()
    {
        try {
            $param = $this->request->post(['photo']);
            UserModel::update($param, ['id' => $this->user->id]);
            return Result::success('已修改');
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }

    }
}
